﻿
using Microsoft.EntityFrameworkCore;

using System;

using System.Linq;

using Xc.DataAccess.DataBases.Logs.Services;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ApplicationDbContextExtension
    {
        /// <summary>
        /// 添加数据库日志服务
        /// <list type="number">
        /// <item>数据库日志服务: <see cref="IDbLogService"/></item>
        /// </list>
        /// </summary>
        /// <typeparam name="TDbContext"></typeparam>
        /// <param name="serviceDescriptors"></param>
        /// <returns></returns>
        public static IServiceCollection AddDbLogService<TDbContext>(this IServiceCollection serviceDescriptors) where TDbContext:DbContext,IDbLog
        {
            serviceDescriptors.AddTransient<IDbLogService, DbLogService<TDbContext>>();
            return serviceDescriptors;
        }
        /// <summary>
        /// 获取数据库日志服务
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static IDbLogService GetDbLogService(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetRequiredService<IDbLogService>();
        }
    }
}
